package fl.ass.service.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cmm.mid.core.framework.page.Pager;
import cmm.service.core.framework.biz.BaseBizImpl;
import cmm.service.core.framework.dao.IBaseDao;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import fl.ass.facade.condition.AssDealSellLossQueryCondition;
import fl.ass.facade.condition.AssDealSellQueryCondition;
import fl.ass.facade.dto.AssDealSellDTO;
import fl.ass.facade.dto.AssDealSellLossDTO;
import fl.ass.service.dao.AssDealSellMapper;
import fl.ass.service.po.AssDealSell;
import fl.ass.service.po.AssDealSellLoss;
import fl.ass.service.service.IAssDealSellLossService;
import fl.ass.service.service.IAssDealSellService;
import fl.ass.service.transform.AssDealSellLossTransform;
import fl.ass.service.transform.AssDealSellTransform;
import fl.ass.service.dao.AssDealSellLossMapper;
/**
 * @Description: 处置-变卖（事业部及优车） 服务层接口实现
 * @Description: 类中已经实现了简单增删改查操作,可以直接使用,如果有需要重写该方法即可：
 * @Description: 1、add(TVO entity) 2、removeById(Long id) 3、modify(DTO entity) 4、selectById(Long id)	5、searchListPage(Pager page) 7、searchList(DTO dto)   
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class AssDealSellLossServiceImpl extends BaseBizImpl<AssDealSellLoss, AssDealSellLossDTO, AssDealSellLossQueryCondition> implements IAssDealSellLossService {
	
	@SuppressWarnings("unused")
	private static final Logger logger = LoggerFactory.getLogger(IAssDealSellLossService.class);
	
	@Autowired
	private AssDealSellLossMapper  AssDealSellLossMapper;
	
	 /**
     * 分页查询所有变卖亏损信息
     * @param page
     * @return
     */
	@Override
	public Pager AssDealSellLossByPage(Pager page) throws BaseException {
		//List<AssDealSellLossDTO> list1 = this.assDealSellMapper.AssDealSellLossByPage(page);
		//List<AssDealSellLossDTO> list1 = this.AssDealSellLossMapper.AssDealSellLossByPage(page);
		List<AssDealSellLoss> list = this.AssDealSellLossMapper.selectListPage(page);
		if(!CollectionUtils.isNotEmpty(list)){
			list = new ArrayList<AssDealSellLoss>();
		}
		/*SysDictionaryDTO dictionary = null;
		for(AssDealCarCostDTO dto : list){
			//处理费用项(ASS0015)
			if(StringUtils.isNotBlank(dto.getCostTypeCd())){
				dictionary = sysDictionaryApiService.getCode(InterfaceConstants.SYS_CODE, InterfaceConstants.ORG_CODE, InterfaceConstants.COST_TYPE_CD, dto.getCostTypeCd());
				if(null != dictionary){
					dto.setCostTypeCd(dictionary.getCodeNm());
				}
			}
		}*/
		page.setResultList(list);
		return page;
	}

	@Override
	public IBaseDao<AssDealSellLoss, AssDealSellLossQueryCondition> getDao() {
		return this.AssDealSellLossMapper;
	}

	@Override
	public List<AssDealSellLossDTO> searchList(AssDealSellLossQueryCondition condition) throws BaseException {
		if(null == condition) return new ArrayList<AssDealSellLossDTO>();
		List<AssDealSellLoss> list = this.AssDealSellLossMapper.selectList(condition);
		return AssDealSellLossTransform.toDTOList(list);
	}

	@Override
	public List<AssDealSellLossDTO> searchLossList(Long sellId)throws BaseException {
		List<AssDealSellLoss> selectList = this.AssDealSellLossMapper.selectLossList(sellId);
		List<AssDealSellLossDTO> dtoList = AssDealSellLossTransform.toDTOList(selectList);
		return dtoList;
	}
	/*新增亏损信息
	 * (non-Javadoc)
	 * @see fl.ass.service.service.IAssDealSellLossService#addassDealSellLoss(fl.ass.facade.dto.AssDealSellLossDTO)
	 */
	@Override
	public Long addassDealSellLoss(AssDealSellLossDTO dto) throws BaseException {
		AssDealSellLoss assDealSellLosspo = AssDealSellLossTransform.toPO(dto);
	    Long id =this.AssDealSellLossMapper.addassDealSellLoss(assDealSellLosspo);
		return id;
	}
	/*修改亏损信息
	 * (non-Javadoc)
	 * @see fl.ass.service.service.IAssDealSellLossService#addassDealSellLoss(fl.ass.facade.dto.AssDealSellLossDTO)
	 */
	@Override
	public Long modifyassDealSellLoss(AssDealSellLossDTO dto) throws BaseException {
	Long id = 	this.AssDealSellLossMapper.modifyassDealSellLoss(AssDealSellLossTransform.toPO(dto));
		return id;
	}

}

